<?php
/**
 * Text element
 *
 */
class ArrowFormCode extends ArrowFormField{
	
	public function configure(){
		parent::configure();	
		$this->addProperties(array(
			"length" => "1,",
			"rexp" => false,
			"mode" => "html"
		));
	}
	
	public function init(){
		parent::init();
		$mode = $this->getProperty("mode");
		
		$jsData = array();
		$jsData["mode"] = $mode;
		$this->registerJsFile( "./server/standardModels/org/arrowplatform/controls/forms/ctrl/javascript/resources/ace/ace.js" );
		$this->registerJsFile( "./server/standardModels/org/arrowplatform/controls/forms/ctrl/javascript/resources/ace/theme-eclipse.js" );
		$this->registerJsFile( "./server/standardModels/org/arrowplatform/controls/forms/ctrl/javascript/resources/ace/mode-$mode.js" );
	
		$this->registerJs( get_class($this), dirname(__FILE__)."/ArrowFormCode.js", '#ctrl-form-code-'.$this->getId(), $jsData);
		
	}
	
	
	public function validate( $proposedValue ){
		return true;
	}
	
	public function generateOutput(){
		$attribuites = array();
		$attribuites["id"] = 'ctrl-form-code-'.$this->getId();
		$attribuites["class"] = "my-ace";


		$str = '<textarea style="display: none;" name="'.$this->getHtmlName().'" id="ctrl-form-code-'.$this->getId().'-area">'.$this->getValue().'</textarea>';
		$str.= '<div '.$this->genTagsFromArray($attribuites).' '.$this->addExternal().'  >';
		$str.=  str_replace( "\t", "    ",htmlentities($this->getValue(), ENT_NOQUOTES, "UTF-8"));
		$str.= "</div>";
		return $str;
	}


}
?>